package com.hello.controller;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;

import org.junit.Test;

import com.github.javafaker.Faker;
public class Java8Stream {
	
			
	public List<Map<String, Object>> getData() {
		Map<String, Object> ms = null;
		List<Map<String,Object>> list = new ArrayList<>();
		Faker faker = new Faker(new Locale("zh-CN"));;
		for(int i = 0; i < 100; i++ ) {
			ms = new HashMap<String, Object>();
			ms.put("name", faker.name().name());
			ms.put("age", faker.number().numberBetween(1, 100));
			ms.put("job", faker.job().field());
			ms.put("class", faker.number().numberBetween(1, 3));
			list.add(ms);
		}
		 return list;
	}

	@Test
	public void testStream() {
		/*List<Map<String, Object>> list = getData();*/
		/*System.out.println(list);
		Stream.iterate(1, item -> item + 1)
        .limit(100)
        .forEach(System.out::println); */
		/*Stream.concat(Stream.of(1,2,3), Stream.of(0,4,5)).forEach(System.out::println);*/
		/*Stream.of(1,2,3,"1",2).distinct().forEach(System.out::println);*/
	  /* Stream.of(getData()).forEach(System.out::println);*/
		/*Stream.concat(Stream.of(getData()), Stream.of(0,4,5)).forEach(System.out::println);*/
		/*Stream.of(list).forEach(System.out::println);
		Stream.of(list).filter(item -> item.get(0).get("name").toString().length()<3).forEach(System.out::println);*/
		/*Stream.of(0,1,2,3,4.5).mapToInt(item -> item.intValue()).forEach(System.out::println);
		Stream.of(0,1,2,3,4.5).mapToDouble(item -> item.doubleValue()).forEach(System.out::println);
		Stream.of(0,1,2,3,4.5).mapToLong(item -> item.longValue()).forEach(System.out::println);*/
		String s = "456";
		String str = null;
	   /* str = Optional.ofNullable(str).orElse(s);
		Optional.ofNullable(str).ifPresent(ss->{
			System.out.println(ss);
		});
		Optional.ofNullable(str).isPresent();*/
	/*	str = "张彪";*/
		/*str = new String("张彪");*/
		/*str = new String("123");*/
		/*System.out.println(Optional.ofNullable(str).hashCode());*/
		//str = Optional.ofNullable(str).orElseGet("程**");
		str = Optional.ofNullable(str).orElse(s);
		System.out.println(str);
		
	}
}
